﻿<template>
	<div class="diBusiness-container">
		<el-dialog v-model="state.isShowDialog" draggable width="769px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" size="default" label-width="80px" :rules="rules"
				:disabled="true">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="请求时间">
							<el-input v-model="state.ruleForm.createTime" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="PID">
							<el-input v-model="state.ruleForm.pid" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="客户">
							<el-input v-model="state.ruleForm.customerName" class="w100" clearable />
						</el-form-item>
					</el-col>


					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="媒体产品">
							<el-input v-model="state.ruleForm.productName" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="手机号码">
							<el-input v-model="state.ruleForm.phone" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="省份">
							<el-input v-model="state.ruleForm.province" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="城市">
							<el-input v-model="state.ruleForm.city" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="运营商">
							<el-input v-model="state.ruleForm.operatorPlatform" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="验证码">
							<el-input v-model="state.ruleForm.onceVerifyCode" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="请求IP">
							<el-input v-model="state.ruleForm.requestIP" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="媒体来源">
							<el-input v-model="state.ruleForm.advSource" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="app包名">
							<el-input v-model="state.ruleForm.advAppPackageName" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="userAgent">
							<el-input v-model="state.ruleForm.userAgent" placeholder="" class="w100" clearable
								type="textarea" style="word-break: break-all;" :autosize="{ minRows: 2 }" />
						</el-form-item>
					</el-col>
					<el-divider border-style="dashed" />
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="发送URL">
							<el-input v-model="state.ruleForm.requestUrl" placeholder="" class="w100" clearable
								type="textarea" style="word-break: break-all;" :autosize="{ minRows: 2 }" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="发送响应">
							<el-input v-model="state.ruleForm.resData" placeholder="" class="w100" clearable type="textarea"
                                style="word-break: break-all;" :autosize="{ minRows: 2 }" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="验证URL">
							<el-input v-model="state.ruleForm.onceVerifyUrl" placeholder="" class="w100" clearable
								type="textarea" style="word-break: break-all;" :autosize="{ minRows: 2 }" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="验证响应">
							<el-input v-model="state.ruleForm.onceVerifyResData" placeholder="" class="w100" clearable
								type="textarea" style="word-break: break-all;" :autosize="{ minRows: 2 }" />
						</el-form-item>
					</el-col>

					<el-divider border-style="dashed" />
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="日志" class="formItemLog">
							<div>
								<span> &nbsp;&nbsp; {{ state.ruleForm.createTime }}</span>
								<div class="phone"> &nbsp;&nbsp;INFO：用户 {{ state.ruleForm.phone }} 发起计费</div>
								<div class="logItem"> &emsp;&emsp; 发送短信Url={{
									state.ruleForm.requestUrl }}</div>
								<div class="logItem"> &emsp;&emsp; 发送短信响应={{
									state.ruleForm.resData }}</div>
								<div class="logItem"> &emsp;&emsp; 提交验证码Url={{
									state.ruleForm.onceVerifyUrl }}</div>
								<div class="logItem"> &emsp;&emsp; 提交验证码响应={{
									state.ruleForm.onceVerifyResData }}</div>
								<div class="logItem"> &emsp;&emsp;</div>
							</div>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" size="default">取 消</el-button>
					<el-button type="primary" @click="submit" size="default">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="editDiBusiness" >
import { reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import type { FormRules } from "element-plus";
import mittBus from '/@/utils/mitt';
import { optionDict } from '/@/const/dict.ts';
import { DiBusiness } from '/@/api/models';
import SysDiBusinessApi from '/@/api/delivery/business';

// 定义变量内容
const props = defineProps({
	title: String,
});
const ruleFormRef = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {} as DiBusiness,
});

// 删除非必填规则
const rules = ref<FormRules>({

});

// 打开弹窗.
const openDialog = (row: DiBusiness) => {
	state.ruleForm = JSON.parse(JSON.stringify(row));
	state.isShowDialog = true;

	optionDict.operatorPlatformDict.map(item => {
		state.ruleForm.operatorPlatform = state.ruleForm.operatorPlatform == item.value ? item.label : state.ruleForm.operatorPlatform;
	})
};

// 关闭弹窗
const closeDialog = () => {
	mittBus.emit('submitRefresh');
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean, fields?: any) => {
		if (valid) {
			let res;
			if (state.ruleForm.id != undefined && state.ruleForm.id > 0) {
				res = await SysDiBusinessApi().editPost(state.ruleForm);
			} else {
				res = await SysDiBusinessApi().addPost(state.ruleForm);
			}
			if (res.data.resCode != '0000')
				ElMessage.error(res.data.resMessage);
			else {
				ElMessage.success("操作成功");
				closeDialog();
			}
		} else {
			ElMessage({
				message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
				type: "error",
			});
		}
	});
};

// 导出对象 将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>

<style lang="scss" scoped>
.higlabel {
    :deep(label) {
		display: flex;
		align-items: center;
	}
}

.formItemLog {
	background-color: #222222;
	width: 100%;

	span {
		font-size: 10px;
		color: #767575;
	}

	.phone {
		font-size: 14px;
		color: #fff;
		line-height: 10px;
	}

	.logItem {
		font-size: 12px;
		line-height: 22px;
	}
}
</style>
